package com.zhudeshuai.zhudemolist.animation;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.zhudeshuai.zhudemolist.R;

import java.util.HashMap;
import java.util.Map;

/**
 * 属性动画学习
 *
 * @author zhudeshuai
 * @since 16/8/13
 */

public class AnimationActivity extends Activity {

    private RecyclerView mRecyclerView;

    private Map<Integer,Class> mData = new HashMap<>();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_animation);
        mRecyclerView = (RecyclerView) findViewById(R.id.recyclerView);
        mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
        initShowData();
        mRecyclerView.setAdapter(new MyAdapter(mData));

    }

    private void initShowData() {
        mData.put(0,ValueAnimatorDemo.class);
        mData.put(1,ObjectAnimatorDemo.class);
    }


    private class MyViewHolder extends RecyclerView.ViewHolder {


        private TextView mContentTv;

        public MyViewHolder(View itemView) {
            super(itemView);
            mContentTv = (TextView) itemView.findViewById(R.id.content_tv);
        }
    }


    private class MyAdapter extends RecyclerView.Adapter<MyViewHolder> {

        private Map<Integer,Class> mShowData;

        private ItemClickListener mItemClickListener;
        public MyAdapter(Map<Integer, Class> showData) {
            mShowData = showData;
        }

        @Override
        public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
            View inflate = LayoutInflater.from(parent.getContext()).inflate(R.layout.view_recycler_item, parent, false);
            return new MyViewHolder(inflate);
        }

        @Override
        public void onBindViewHolder(MyViewHolder holder, int position) {
            Class<Activity> activityClass = mShowData.get(position);
            holder.mContentTv.setText(activityClass.getSimpleName());
            holder.itemView.setOnClickListener(new OnItemClickListener(activityClass));
        }

        @Override
        public int getItemCount() {
            return mShowData.size();
        }


        private class OnItemClickListener implements View.OnClickListener {
            private Class<Activity> mActivityClass;

            public OnItemClickListener(Class<Activity> tag) {
                mActivityClass = tag;
            }

            @Override
            public void onClick(View v) {
                Intent intent = new Intent(AnimationActivity.this, mActivityClass);
                startActivity(intent);
            }
        }
    }


    private interface ItemClickListener {
        void itemClick();
    }






    public static void open(Activity activity){
        activity.startActivity(new Intent(activity,AnimationActivity.class));
    }
}
